# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin

# Register your models here.
from mock.models import MockData


@admin.register(MockData)
class MockAdmin(admin.ModelAdmin):
    list_display = (
        'project_name', 'route', 'kind', 'enable'
    )

    list_per_page = 15

    actions = ['close_api', 'open_api']

    def close_api(self, request, queryset):
        rows_updated = queryset.update(enable=False)
        message = "关闭了{}个Api".format(rows_updated)
        self.message_user(request, message)

    def open_api(self, request, queryset):
        rows_updated = queryset.update(enable=True)
        message = "打开了{}个Api".format(rows_updated)
        self.message_user(request, message)

    close_api.short_description = "关闭选中Api"
    open_api.short_description = "打开选中Api"
